package org.handover.repository;

import org.handover.domain.Role;
import org.handover.domain.User;
import org.handover.domain.UserGroup;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<User, Long>{

    List<User> findAllByEnable(Boolean enable);

    Boolean existsByUsername(String username);
    Boolean existsByIdNotAndUsername(Long id, String username);
    User findByUsername(String username);
    List<User> findByRoleSet_RoleNotIn(List<String> roleList);
    @Modifying
    @Query(value = "update User u set u.username=:username,u.enable=:enable,u.userGroup=:userGroup where u=:user")
    Integer updateUser(@Param(value = "username") String username, @Param(value = "enable") Boolean enable, @Param(value = "userGroup") UserGroup userGroup, @Param(value = "user") User user);

    //@Modifying
   //@Query(value = "update User u set u.username=?1,enable=?2 where id=?3",nativeQuery = true)
    //Integer updateUser(User user);
}
